# -*- coding: utf-8 -*-
"""
逻辑回归添加多项式特征
Created on Mon Apr 23 15:07:00 2018

@author: Allen
"""
import numpy as np
import matplotlib.pyplot as plt

np.random.seed( 666 )
X = np.random.normal( 0, 1, size = ( 200, 2 ) )
y = np.array( X[:, 0]**2 + X[:, 1]**2 < 1.5, dtype = "int" )


plt.scatter( X[y==0, 0], X[y==0, 1] )
plt.scatter( X[y==1, 0], X[y==1, 1] )
plt.show()

# 
from playML.LogisticRegression import LogisticRegression
log_reg = LogisticRegression()
log_reg.fit( X, y )
print( log_reg.score( X, y ) ) # 0.605

from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.preprocessing import PolynomialFeatures

def PolynomialLogisticRegression( degree ):
    return Pipeline([
            ( "poly", PolynomialFeatures( degree ) ),
            ( "std_scaler", StandardScaler() ),
            ( "log_reg", LogisticRegression() )
            ])
    
poly_log_reg = PolynomialLogisticRegression( 2 )
poly_log_reg.fit( X, y )
print( poly_log_reg.score( X, y ) ) # 0.95